package com.rxt.thermopro

import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.DisplayMetrics
import com.app.common.openActivity
import com.rxt.thermopro.ui.activity.DeviceListActivity

class LaunchActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initFontScale()
        Handler(Looper.getMainLooper()).postDelayed({
            openActivity(DeviceListActivity::class.java)
            finish()
        }, 1500)
    }

    private fun initFontScale() {
        val configuration = resources.configuration;
        val fontScale = configuration.fontScale
        val densityDpi = configuration.densityDpi
        println("===fontScale=$fontScale  densityDpi=$densityDpi")
        val newFont = if (fontScale > 1F) {
            (fontScale - 1) / 2 + 1
        } else {
            fontScale
        }
        configuration.fontScale = newFont   //0.85:小号  1:标准  1.25:大号  1.4:巨无霸
        if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.N){
            if (resources.displayMetrics.densityDpi != DisplayMetrics.DENSITY_DEVICE_STABLE) {
                configuration.densityDpi = DisplayMetrics.DENSITY_DEVICE_STABLE // 恢复显示大小
            }
        }
//        resources.updateConfiguration(configuration, resources.displayMetrics)
//        createConfigurationContext(configuration)
    }
}